package com.csh.szhm.activity;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.android.volley.Request.Method;
import com.csh.szhm.R;
import com.csh.szhm.adapter.SzhmShopDetailAdapter;
import com.csh.szhm.http.HttpCallBackUi;
import com.csh.szhm.http.HttpRequestTool;
import com.csh.szhm.http.HttpUrls;
import com.csh.szhm.module.shop.SzhmShopDetailBean;
import com.csh.szhm.utils.AppConfig;
import com.csh.szhm.utils.DebugUntil;
import com.google.gson.reflect.TypeToken;

public class SzhmShopDetailActivity extends MyRefreshBaseActivity<String>
		implements OnClickListener {
	private String shopId;
	private int[] layArr = new int[] { R.id.detail_buttom_1,
			R.id.detail_buttom_2, R.id.detail_buttom_3, R.id.detail_buttom_4 };
	private String[] txtArr = new String[] { "预定", "点评", "关注", "分享" };
	private int[] resArr = new int[] { R.drawable.dianp_bg,
			R.drawable.dianp_bg, R.drawable.d_icon_like, R.drawable.shared_bg };

	@Override
	protected void init() {
		shopId = getIntent().getStringExtra("id");
		initContentView(R.layout.szhm_shop_detail_main_layout);
		setButtomView();
		super.init();
		mAdapter = new SzhmShopDetailAdapter(this);
		mLikeListView.setAdapter(mAdapter);
		mLikeListView.setCanRefresh(false);
		getDetialData();
	}

	private void getDetialData() {
		HttpRequestTool<SzhmShopDetailBean> http = new HttpRequestTool<SzhmShopDetailBean>();
		TypeToken<SzhmShopDetailBean> ty = new TypeToken<SzhmShopDetailBean>() {
		};
		http.setHttpCallBackUi(new HttpCallBackUi<SzhmShopDetailBean>() {

			@Override
			public void success(SzhmShopDetailBean data) {
				dissmisCustomProgressDialog();
				if (data != null) {
					((SzhmShopDetailAdapter) mAdapter).addDetailData(data);
					setMyTitle(data.getFirmInfo().get(0).getFirmTitle());
				}
			}

			@Override
			public void requestType(String Type) {
			}

			@Override
			public void failed(VolleyError error) {
				dissmisCustomProgressDialog();
			}
		});
		http.cloneRequest(Method.GET, HttpUrls.mShopDetail + shopId, ty,
				getClass().getSimpleName(), "SEARCH");
		super.requestNet();
	}

	@Override
	protected void requestNet() {
		super.requestNet();
	}

	private void setButtomView() {
		LinearLayout.LayoutParams lParams = new LinearLayout.LayoutParams(
				AppConfig.getScreenWidth() / 12,
				AppConfig.getScreenWidth() / 12);
		lParams.topMargin = 10;
		for (int i = 0; i < layArr.length; i++) {
			ImageView img = (ImageView) findViewById(layArr[i]).findViewById(
					R.id.main_center_img_id);
			img.setLayoutParams(lParams);
			TextView txt = (TextView) findViewById(layArr[i]).findViewById(
					R.id.main_center_txt_id);
			findViewById(layArr[i]).findViewById(R.id.main_center_root_id)
					.setOnClickListener(this);
			findViewById(layArr[i]).findViewById(R.id.main_center_root_id)
					.setTag(i);
			txt.setTextColor(getResources().getColor(R.color.main_text_color));
			img.setBackgroundResource(resArr[i]);
			txt.setText(txtArr[i]);
		}
	}

	@Override
	public void onClick(View v) {
		if (v.getId() == R.id.main_center_root_id) {
			DebugUntil.createInstance().toastStr("功能暂未开放~~");
		}

	}

}
